package code;
/*
 * 作业:
 * 1.作业定义一个方法,把数组{1,2,3}按照指定格式拼接成一个字符串,格式参照如下:[word#word2#word3]
 * 2.获取指定字符串,大写字母,小写字母,数字的个数
 * 3.将字符串中,第一个字母转换成大写,其他字母转化成小写,并打印改变后的字符串
 * 4.查询大字符串中,出现指定小字符串中次数
 * 如:"hellojava,nihaojava,zhenhaojava,dajiahaojava"
 * "java"
 * 4次
 */
public class Work_20200227 {
    public static void main(String[] args) {
     //1
        printArray();
     //2
        subStr();
     //3
        changeLetter();
     //4
        findStr();

    }

    public static void printArray(){
        int[] num = {1,2,3};
        System.out.print("[");
        for (int i=0;i<num.length;i++){
            if (i == num.length - 1){
                System.out.println(num[i]+"]");
            }else{
                System.out.print(num[i]+"#");
            }
        }
    }

    public static void subStr(){
        int smallCount = 0;
        int bigCount = 0;
        int numCount = 0;

        String str = "abc231gggdeABdCDE12fGDg345";
        for (int i=0;i<str.length();i++){
            String subStr = str.substring(i,i+1);
            char[] subchar = subStr.toCharArray();
//           System.out.println(subchar);
            if (subchar[0] >= 'A' && subchar[0] <= 'Z'){
                bigCount++;
            }
            if (subchar[0] >= 'a' && subchar[0] <= 'z'){
                smallCount++;
            }
            if (subchar[0] >= '0' && subchar[0] <= '9'){
                numCount++;
            }
        }
        System.out.println("大写字母有:"+bigCount+"个");
        System.out.println("小写字母有:"+smallCount+"个");
        System.out.println("数字有:"+numCount+"个");
    }

    public static void changeLetter(){
        String str = "abc231gggdeABdCDE12fGDg345";
        System.out.println(str.substring(0,1).toUpperCase()+str.substring(1).toLowerCase());
    }

    public static void findStr(){
        String str = "hellojava,nihaojava,zhenhaojava,dajiahaojava";
        int count = 0;
        String findStr = "zhenj";
        for (int i=0;i<str.length()-findStr.length()+1;i++){
            System.out.println(str.substring(i,i+findStr.length()));
            if (findStr.equals(str.substring(i,i+findStr.length()))){
                count++;
            }
        }
        System.out.println(findStr+"出现次数有"+count+"次");
    }
}
